//
//  RealTimeCell.m
//  mendianjieke
//
//  Created by 响当当 on 7/30/19.
//  Copyright © 2019 dongzheng. All rights reserved.
//

#import "RealTimeCell.h"
#import "ProgressView.h"

@interface RealTimeCell()
@property (nonatomic, strong)UIImageView *expressionImageView;//表情
@property (nonatomic, strong)UIImageView *headImage;//头像
@property (nonatomic, strong)UILabel *subTitleLabel;//副标题
@property (nonatomic, strong)UIButton *normalButton;//基本状态
@property (nonatomic, strong)UIButton *talkAttackButton;//基本状态
@property (nonatomic, strong)ProgressView *progressView;
@property (nonatomic, strong)UIImageView *customerImageView;
@property (nonatomic, strong)UIButton *serviceCustomerButton;//接客
@end

@implementation RealTimeCell

- (UIImageView *)expressionImageView
{
    if (!_expressionImageView)
    {
        UILabel *titleLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus,14*kUIScaleBasePlus,80*kUIScaleBasePlus,24*kUIScaleBasePlus)
                                               textAligment:NSTextAlignmentLeft
                                                   textClor:LCHexColor(0x000000)
                                                   textFont:17*kUIScaleBasePlus];
        titleLabel.text = @"来客啦！";
        [self.contentView addSubview:titleLabel];
        
        _expressionImageView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(titleLabel.frame)-3*kUIScaleBasePlus,16*kUIScaleBasePlus,20*kUIScaleBasePlus,20*kUIScaleBasePlus)];
        _expressionImageView.layer.cornerRadius = _headImage.frame.size.width/2;
//        _expressionImageView.backgroundColor = JSAMainColor;
    }
    return _expressionImageView;
}

- (UIImageView *)headImage
{
    if (!_headImage)
    {
        _headImage = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-32*kUIScaleBasePlus,CGRectGetMaxY(self.expressionImageView.frame)+17*kUIScaleBasePlus,32*kUIScaleBasePlus,32*kUIScaleBasePlus)];
        _headImage.layer.cornerRadius = _headImage.frame.size.width/2;
//        _headImage.backgroundColor = JSAMainColor;
    }
    return _headImage;
}

- (UILabel *)subTitleLabel
{
    if (!_subTitleLabel)
    {
        _subTitleLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.headImage.frame)+5*kUIScaleBasePlus,CGRectGetMaxY(self.expressionImageView.frame)+23*kUIScaleBasePlus,40*kUIScaleBasePlus, 20*kUIScaleBasePlus)
                                          textAligment:NSTextAlignmentLeft
                                              textClor:LCHexColor(0x000000)
                                              textFont:13*kUIScaleBasePlus];;
    }
    return _subTitleLabel;
}

- (UIButton *)normalButton
{
    if (!_normalButton)
    {
        _normalButton = [Utilties creatButtonWithFrame:CGRectMake(SCREEN_WIDTH/2,CGRectGetMaxY(self.headImage.frame)+16*kUIScaleBasePlus,75*kUIScaleBasePlus,25*kUIScaleBasePlus)
                                          textAligment:UIControlContentHorizontalAlignmentCenter
                                                  text:@"性别"
                                              textClor:LCHexColor(0x282828)
                                             buttonBGC:[UIColor clearColor]
                                              textFont:13*kUIScaleBasePlus
                                                target:self
                                                method:@selector(normalClcik)];
        _normalButton.enabled = NO;
//        _normalButton.layer.masksToBounds = YES;
//        _normalButton.layer.borderWidth = 1;
//        _normalButton.layer.borderColor = LCHexColor(0xFF7A17).CGColor;
        
//        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_normalButton.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(2, 2)];
//        CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
//        maskLayer.frame = _normalButton.bounds;
//        maskLayer.path = maskPath.CGPath;
//        _normalButton.layer.mask = maskLayer;
    
    }
    return _normalButton;
}


- (UIButton *)talkAttackButton
{
    if (!_talkAttackButton)
    {
        _talkAttackButton = [Utilties creatButtonWithFrame:CGRectMake(SCREEN_WIDTH/2-75*kUIScaleBasePlus,CGRectGetMaxY(self.headImage.frame)+16*kUIScaleBasePlus,75*kUIScaleBasePlus,25*kUIScaleBasePlus)
                                          textAligment:UIControlContentHorizontalAlignmentCenter
                                                  text:@"年龄"
                                              textClor:LCHexColor(0x282828)
                                             buttonBGC:[UIColor clearColor]
                                              textFont:13*kUIScaleBasePlus
                                                target:self
                                                method:@selector(talkAttackClick)];
        _talkAttackButton.enabled = NO;
//        _talkAttackButton.layer.masksToBounds = YES;
//        _talkAttackButton.layer.borderWidth = 1;
//        _talkAttackButton.layer.borderColor = LCHexColor(0xFF7A17).CGColor;
//
//        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_talkAttackButton.bounds byRoundingCorners:UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii:CGSizeMake(2, 2)];
//        CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
//        maskLayer.frame = _talkAttackButton.bounds;
//        maskLayer.path = maskPath.CGPath;
//        _talkAttackButton.layer.mask = maskLayer;
        
    }
    return _talkAttackButton;
}

- (ProgressView *)progressView
{
    if (!_progressView)
    {
        _progressView = [[ProgressView alloc]init];
    }
    return _progressView;
}

- (UIImageView *)customerImageView
{
    if (!_customerImageView)
    {
        _customerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15*kUIScaleBasePlus,202*kUIScaleBasePlus,200*kUIScaleBasePlus,100*kUIScaleBasePlus)];
        _customerImageView.layer.masksToBounds = YES;
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_customerImageView.bounds byRoundingCorners:UIRectCornerTopLeft| UIRectCornerBottomLeft cornerRadii:CGSizeMake(3, 3)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
        maskLayer.frame = _customerImageView.bounds;
        maskLayer.path = maskPath.CGPath;
        _customerImageView.layer.mask = maskLayer;
        
//        _customerImageView.backgroundColor = [UIColor blueColor];
    }
    return _customerImageView;
}

- (UIButton *)serviceCustomerButton
{
    if (!_serviceCustomerButton)
    {
        _serviceCustomerButton = [Utilties creatButtonWithFrame:CGRectMake(CGRectGetMaxX(self.customerImageView.frame), 202*kUIScaleBasePlus,125*kUIScaleBasePlus,100*kUIScaleBasePlus)
                                                   textAligment:UIControlContentHorizontalAlignmentCenter
                                                           text:@"接客"
                                                       textClor:LCHexColor(0xFFFFFF)
                                                      buttonBGC:LCHexColor(0xFF7A17)
                                                       textFont:17*kUIScaleBasePlus
                                                         target:self
                                                         method:@selector(serviceCustomer)];
        
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_serviceCustomerButton.bounds byRoundingCorners:UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii:CGSizeMake(3, 3)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
        maskLayer.frame = _serviceCustomerButton.bounds;
        maskLayer.path = maskPath.CGPath;
        _serviceCustomerButton.layer.mask = maskLayer;
        _serviceCustomerButton.titleLabel.numberOfLines = 0;
    }
    return _serviceCustomerButton;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self.contentView addSubview:self.expressionImageView];
        [self.contentView addSubview:self.headImage];
        [self.contentView addSubview:self.subTitleLabel];
        [self.contentView addSubview:self.normalButton];
        [self.contentView addSubview:self.talkAttackButton];
        [self.contentView addSubview:self.progressView];
        [self.contentView addSubview:self.customerImageView];
        [self.contentView addSubview:self.serviceCustomerButton];
    }
    return self;
}


- (void)normalClcik
{
    
}

- (void)talkAttackClick
{
    
}

- (void)serviceCustomer
{
    
}

- (void)setModel:(RealTimeModel *)model
{
    _model = model;

    SummaryModel *smodel = [[SummaryModel alloc]initWithDic:model.summary];
    [self.normalButton setTitle:[NSString stringWithFormat:@"年龄：%ld",smodel.age.integerValue] forState:UIControlStateNormal];
    [self.talkAttackButton setTitle:[NSString stringWithFormat:@"年龄：%@",smodel.gender.integerValue == 0 ? @"女" : @"男"] forState:UIControlStateNormal];

    
    if (model.serveState.integerValue == 1)
    {
        
        [self.progressView getRealTimeFrame:CGRectMake(0,CGRectGetMaxY(self.talkAttackButton.frame)+20*kUIScaleBasePlus,self.frame.size.width,50*kUIScaleBasePlus) info:@[@"首次到店",@"等待服务"]];
    }
    else
    {
        
        [self.progressView getRealTimeFrame:CGRectMake(0,CGRectGetMaxY(self.talkAttackButton.frame)+20*kUIScaleBasePlus,self.frame.size.width,50*kUIScaleBasePlus) info:@[[NSString stringWithFormat:@"忠诚度：%.1f",smodel.loyalty.floatValue],[NSString stringWithFormat:@"生命周期：%@",smodel.lifeCycle],smodel.label]];
        [self.serviceCustomerButton setTitle:[NSString stringWithFormat:@"已被%@于%@接客",model.waiterName,[Utilties getTime:model.serveTime.stringValue]] forState:UIControlStateNormal];
        [self.serviceCustomerButton.titleLabel setFont:[UIFont systemFontOfSize:12*kUIScaleBasePlus]];
    }
    
    self.subTitleLabel.text = model.customerType.integerValue == 1 ? @"新顾客" : @"老顾客";
    
    NSArray *arr = [model.photo componentsSeparatedByString:@","];
    
    NSData *decodeData = [[NSData alloc]initWithBase64EncodedString:arr[1] options:(NSDataBase64DecodingIgnoreUnknownCharacters)];
    
    self.customerImageView.image = [UIImage imageWithData:decodeData];
    self.headImage.image = [UIImage imageWithData:decodeData];
        
        switch (model.expression.integerValue)
        {
            case 0:
            {

            }
                    break;
            case 1:
            {
                self.expressionImageView.image = [UIImage imageNamed:@"jingya"];
                
            }
                break;
            case 2:
            {
                self.expressionImageView.image = [UIImage imageNamed:@"pingjing"];
                
            }
                break;
                default:
                    break;
        }
}
@end
